package edu.xhu.biliuser;

import cn.hutool.core.util.IdUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import edu.xhu.api.id.IdClient;
import edu.xhu.api.video.VideoClient;

import edu.xhu.biliuser.mapper.BiliUserConfigMapper;
import edu.xhu.biliuser.mapper.BiliUserInfoMapper;
import edu.xhu.biliuser.mapper.BiliUserMapper;
import edu.xhu.model.behavior.pojos.BiliUserComment;
import edu.xhu.model.behavior.vo.CommentTree;
import edu.xhu.model.biliuser.enums.AuthType;
import edu.xhu.model.biliuser.enums.ExperienceEnum;
import edu.xhu.model.biliuser.enums.LevelEnum;
import edu.xhu.model.biliuser.enums.MegaType;
import edu.xhu.model.biliuser.pojos.BiliUser;
import edu.xhu.model.biliuser.pojos.BiliUserConfig;
import edu.xhu.model.biliuser.pojos.BiliUserInfo;
import edu.xhu.model.common.dtos.ResponseResult;
import edu.xhu.model.common.enums.AppHttpCodeEnum;
import edu.xhu.model.common.enums.IsFlagEnum;
import edu.xhu.model.video.pojos.BiliVideo;
import edu.xhu.utils.common.SaltGenerator;
import edu.xhu.utils.validator.PhoneValidator;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.DigestUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

@SpringBootTest(classes = BilibiliUserApplication.class)
@RunWith(SpringRunner.class)
public class addDataToUser {

    @Autowired
    private BiliUserMapper biliUserMapper;

    @Autowired
    private BiliUserInfoMapper biliUserInfoMapper;

    @Autowired
    private BiliUserConfigMapper biliUserConfigMapper;

    @Autowired
    private IdClient idClient;



    @Test
    public void addSonComment() {

        for(int i=0;i<10;++i){
            long id = Long.parseLong(idClient.getSnowflakeDistributedId().getData().toString());
            String salt = SaltGenerator.generateSalt();
            StringBuilder sb = new StringBuilder();
            Random random = new Random();

            for (int j = 0; j < 11; j++) {
                int digit = random.nextInt(10);
                sb.append(digit);
            }

            String result = sb.toString();

            BiliUser biliUser = new BiliUser(id
                    , salt
                    , DigestUtils.md5DigestAsHex(("123" + salt).getBytes())
                    , "bili_" + IdUtil.simpleUUID()
                    , result
                    , new Date()
                    , new Date()
                    , new Date()
                    , "ip", "ip");
            biliUserMapper.insert(biliUser);
            BiliUserInfo biliUserInfo= new BiliUserInfo(id
                    , "bili_" + PhoneValidator.maskPhoneNumber(result)
                    , "默认头像地址"
                    , LevelEnum.LEVEL_ZERO.getLevel()
                    , ExperienceEnum.LOGIN.getExperience()
                    , new Date());
            biliUserInfoMapper.insert(biliUserInfo);
            BiliUserConfig biliUserConfig=new BiliUserConfig(id
                    , AuthType.NORMAL.getCode()
                    , MegaType.COMMON.getCode()
                    , ""
                    , new Date()
                    , 1);
            biliUserConfigMapper.insert(biliUserConfig);
        }
    }

}
